package com.lazypeople.view;

import javafx.application.Platform;
import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javafx.scene.control.ProgressBar;
import javafx.scene.image.ImageView;

public class SplashController {
    @FXML
    private ImageView splashImage;
    @FXML
    private ProgressBar progressBar;
    @FXML
    private Label progressLabel;

    public void initialize() {
        // 设置启动图片
        splashImage.setImage(new javafx.scene.image.Image(
                getClass().getResourceAsStream("/assets/splash.png"),
                400, 300,
                true,
                true));
        // 初始化进度条为0
        progressBar.setProgress(0);

    }

    public void updateProgress(double progress, String message) {
        // 确保UI更新在JavaFX应用线程中执行
        Platform.runLater(() -> {
            // 限制进度值在0-1之间
            double clampedProgress = Math.max(0, Math.min(1, progress));
            progressBar.setProgress(clampedProgress);
            progressLabel.setText(message + " " + (int) (clampedProgress * 100) + "%");
        });
    }
}